package com.suray.wcs.service.test.action.checkmap.core;

import java.util.ArrayList;
import java.util.List;

public class GroundCodeContainer {
    /**
     * 当前检测的地码下标
     */
    int codeIndex;

    /**
     * 当前容器所有地码
     */
    List<String> groundCodes;

    public GroundCodeContainer(List<String> groundCode) {
        this.groundCodes = groundCode;
        codeIndex = 0;
    }

    /**
     * 下一个地码的下标
     * @return
     */
    public int nextCode() {
        return ++codeIndex;
    }

    public int getCodeIndex() {
        return codeIndex;
    }

    public void setCodeIndex(int codeIndex) {
        this.codeIndex = codeIndex;
    }

    /**
     * 根据下标获取对应的地码
     * @param index
     * @return
     */
    public String get(int index) {
        if (index >= groundCodes.size() || index < 0) {
            return null;
        }

        return groundCodes.get(index);
    }

    /**
     * 是否包含地码
     * @param groundCode
     * @return
     */
    public boolean contains(String groundCode) {
        return this.groundCodes.contains(groundCode);
    }

    /**
     * 获取地码对应的下标
     * @param groundCode
     * @return
     */
    public int indexOf(String groundCode) {
        return this.groundCodes.indexOf(groundCode);
    }

    /**
     * 获取当前下表对应的地码
     * @return
     */
    public String getGroundCode() {
        return groundCodes.get(codeIndex);
    }

    /**
     * 获取上一个下表对应的地码
     * codeIndex = 0,则返回null
     * @return
     */
    public String getPreGroundCode() {
        if (codeIndex == 0) {
            return null;
        }

        return groundCodes.get(codeIndex - 1);
    }

    /**
     * 获取地码数量
     * @return
     */
    public int size() {
        return groundCodes.size();
    }

    public List<String> getGroundCodes() {
        return groundCodes;
    }

    /**
     * 地码校验是否结束
     * @return
     */
    public boolean isEnd() {
        return codeIndex >= groundCodes.size();
    }

    /**
     * 获取剩余的地码
     * @return
     */
    public List<String> getLeftGroundCodes() {
        List<String> leftGroundCodes = new ArrayList<>();

        for (int i = codeIndex; i < groundCodes.size(); i++) {
            leftGroundCodes.add(groundCodes.get(i));
        }

        return leftGroundCodes;
    }

    @Override
    public String toString() {
        return "GroundCodeContainer{" +
                "codeIndex=" + codeIndex +
                ", groundCodes=" + groundCodes +
                '}';
    }
}
